//
//  RWIncrementBillView.m
//  RedWine
//
//  Created by Liufangfang on 2017/1/14.
//  Copyright © 2017年 HuiBangKe. All rights reserved.
//

#import "RWIncrementBillView.h"

@interface RWIncrementBillView ()<UITextFieldDelegate>{
    
    NSArray *incrementBillTitles;
    NSArray *incrementBillPlaceholders;
}

@end

@implementation RWIncrementBillView

- (instancetype)init{
    
    self = [super init];
    
    if (self) {
        [self setincrementBillUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        [self setincrementBillUI];
    }
    return self;
}

#pragma mark - Load Data Methods

- (void)initObjects{
    
    incrementBillTitles = @[@"发票抬头：", @"寄货地址：", @"公司电话：", @"开户行：", @"银行账号：", @"税务号："];
    incrementBillPlaceholders = @[@"请输入正确的公司名称", @"请输入正确的寄货地址", @"请输入正确公司电话", @"请输入正确的开户行", @"请输入正确的银行账号", @"请输入正确的税务号"];
}

#pragma mark - Config UI Methods

- (void)setincrementBillUI{
    
    [self initObjects];
    
    _incrementBillTV = [[FTYTouchTableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
    [self addSubview:_incrementBillTV];
//    _incrementBillTV.backgroundColor = [FTYColor getEEEEEEColorWithAlpha:1.];
    _incrementBillTV.separatorStyle = UITableViewCellSeparatorStyleNone;
    _incrementBillTV.scrollEnabled = NO;
    _incrementBillTV.dataSource = self;
    _incrementBillTV.delegate = self;
    _incrementBillTV.touchDelegate = self;
}

#pragma mark - Notificaiton Method

#pragma mark - Notificaiton Invoke Methods

#pragma mark - <UITableViewDataSource>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60.*FTY_HEIGHT_BASE;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * const billID = @"billID";
    UITableViewCell *billCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:billID];
    billCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSInteger row = indexPath.row;
    billCell.textLabel.text = incrementBillTitles[row];
    billCell.textLabel.font = FTY_FONTTSIZE(15);
    
    UITextField *textField = [[UITextField alloc] init];
    [billCell addSubview:textField];
    textField.placeholder = incrementBillPlaceholders[row];
    textField.font = FTY_FONTTSIZE(15);
    textField.textColor = [FTYColor grayColor];
    textField.delegate = self;
    [textField sizeToFit];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(billCell);
        make.left.mas_equalTo(90.*FTY_WIDTH_BASE);
        make.right.mas_offset(-10.*FTY_WIDTH_BASE);
        make.height.mas_equalTo(billCell.mas_height);
    }];
    
    switch (row) {
        case 0:
            _billTaiTouTF = textField;
            break;
        case 1:
            _addrTF = textField;
            break;
        case 2:
            textField.keyboardType = UIKeyboardTypeNumberPad;
            _phoneNumTF = textField;
            break;
        case 3:
            _bankTF = textField;
            break;
        case 4:
            textField.keyboardType = UIKeyboardTypeNumberPad;
            _bankCardTF = textField;
            break;
        case 5:
            textField.keyboardType = UIKeyboardTypeNumberPad;
            _taxIDTF = textField;
            break;
            
        default:
            break;
    }
    
    //底部线
    UIView *line = [[UIView alloc] init];
    [billCell addSubview:line];
    line.backgroundColor = [UIColor lightGrayColor];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_offset(0);
        make.height.mas_offset(.5*FTY_HEIGHT_BASE);
    }];
    
    return billCell;
}

#pragma mark - <UITableViewDelegate>

#pragma mark - <FTYTouchTableViewDelegate>

- (void)tableView:(UITableView *)tableView touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    [_billTaiTouTF resignFirstResponder];
    [_addrTF resignFirstResponder];
    [_phoneNumTF resignFirstResponder];
    [_bankTF resignFirstResponder];
    [_bankCardTF resignFirstResponder];
    [_taxIDTF resignFirstResponder];
}

#pragma mark - <UITextFieldDelegate>

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [_billTaiTouTF resignFirstResponder];
    [_addrTF resignFirstResponder];
    [_phoneNumTF resignFirstResponder];
    [_bankTF resignFirstResponder];
    [_bankCardTF resignFirstResponder];
    [_taxIDTF resignFirstResponder];
    
    return YES;
}


@end
